package ar.edu.unrn.lia.service.impl;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;
import javax.inject.Named;

import org.springframework.transaction.annotation.Transactional;

import ar.edu.unrn.lia.dao.GaranteDAO;
import ar.edu.unrn.lia.model.Garante;
import ar.edu.unrn.lia.service.CuentaService;
import ar.edu.unrn.lia.service.GaranteService;

@Named("garanteService")
public class GaranteServiceImpl implements GaranteService, Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -1994947401895935099L;
	@Inject
	GaranteDAO entityDAO;

	@Inject
	CuentaService cuentaService;

	public GaranteDAO getEntityDAO() {
		return entityDAO;
	}

	@Transactional(readOnly = true)
	public Long getCount(Map<String, String> filters) {
		return getEntityDAO().count(
				getEntityDAO().getSearchPredicates(getEntityDAO().rootCount(),
						filters));
	}

	@Transactional(readOnly = true)
	public List<Garante> getList(Integer page, Integer pagesize,
			Map<String, String> filters, String sortField, Boolean asc) {
		return getEntityDAO().listwithPag(
				getEntityDAO().getSearchPredicates(getEntityDAO().rootCount(),
						filters), page, pagesize, sortField, asc);
	}
	@Transactional(readOnly = true)
	public List<Garante> getList(Integer page, Integer pagesize,
			Map<String, String> filters, Map<String, Boolean> sorts) {
		return getEntityDAO().listwithPag(
				getEntityDAO().getSearchPredicates(getEntityDAO().rootCount(),
						filters), page, pagesize, sorts);
	}
	
	

	@Transactional
	public void save(Garante entity) {
		cuentaService.crearCuenta(entity);
		getEntityDAO().create(entity);
	}

	@Transactional
	public void delete(Garante entity) {
		getEntityDAO().delete(entity);
	}

	@Transactional
	public void update(Garante entity) {
		getEntityDAO().update(entity);
	}

	public Garante getEntityById(Long id) {
		return getEntityDAO().read(id);
	}

	public List<Garante> getAll() {
		return getEntityDAO().findAll();
	}

	public List<Garante> findByQuery(String query, String propertyFilter,
			String orderDirection) {
		return getEntityDAO()
				.findByQuery(query, propertyFilter, orderDirection);
	}

	public CuentaService getCuentaService() {
		return cuentaService;
	}

	public void setCuentaService(CuentaService cuentaService) {
		this.cuentaService = cuentaService;
	}


}